<?php

namespace plugin\laoha\app\admin\controller;

use plugin\laoha\app\model\Comment;
use plugin\laoha\app\validate\ContentValidate;
use support\Request;

class CommentController extends CrudController
{
  protected $noNeedAuth = ['select', 'show', 'list', 'check'];
  protected $dataLimit = "auth"; //null

  public function __construct()
  {
    // 构造方法，实例化Comment模型和ContentValidate验证器
    $this->model = new Comment;
    $this->validate = new ContentValidate;
  }

  public function index(Request $request)
  {
    if (empty(config('plugin.laoha.set.app.post.comment'))) {
      return ' 文章评论未开启';
    }
    // 处理首页请求
    // 参数: $request - 请求对象
    // 返回: 视图'comment/index'及权限
    $params = ['rules' => $this->getRules(),'cur_status'=>$request->input('status',0)];
    return view('comment/index', ['params' => $params]);
  }

  public function list(Request $request)
  {
    $this->set = ['no_where' => 'id', 'root' => 'post','page_type'=>1,'data_format' => 'list'];
    $this->builder = $this->model->with(['user:id,nickname,avatar','root:id,title,status']);

    return parent::list($request);
    //return json_ok($data);
  }
}
